package MediaOnline.General;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

import android.graphics.drawable.Drawable;

public class downloadImage {
	//Download thumbail image
			public Drawable downloadDrawable(final String url) {  
				try {
					InputStream is = getInputStream(url);
				
			        Drawable drawable = Drawable.createFromStream(is, url);
			        
			        return drawable;  
				} catch (MalformedURLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				return null;
			}  

			public InputStream getInputStream(String urlString) throws MalformedURLException, IOException {
			    URL url = new URL(urlString);
			    URLConnection connection;
			    connection = url.openConnection();
			    connection.setUseCaches(true); 
			    connection.connect();
			    InputStream response = connection.getInputStream();

			    return response;
			}
}
